package com.sun.androidexerciseproject.widget.app;

import android.app.Application;

import com.sun.androidexerciseproject.widget.R;
import com.sun.androidexerciseproject.widget.android.test.Lesson1Activity;
import com.sun.androidexerciseproject.widget.util.AppPackage;
import com.sun.androidexerciseproject.widget.util.ExceptionHandler;
import com.sun.androidexerciseproject.widget.util.LogUtil;

import cn.aofeng.threadpool4j.ThreadPoolManager;
import me.goldze.mvvmhabit.base.BaseApplication;
import me.goldze.mvvmhabit.crash.CaocConfig;
import me.goldze.mvvmhabit.utils.KLog;

/**
 * Created by Steven on 2016/8/15 0015.
 */
public class WidgetApplication extends BaseApplication {
    @Override
    public void onCreate() {
        super.onCreate();
        ExceptionHandler.getInstance().init(getApplicationContext());
        init();
        mvvmInit();
        //todo,用线程池，需要初始化
        ThreadPoolManager.getSingleton().init(this);
    }

    private void init() {
        AppPackage.getInstance().init(getApplicationContext());
        AppPackage appPackage = AppPackage.getInstance();
        String versionCode = appPackage.getVersionCode();
        String versionName = appPackage.getVersionName();
        String packName = appPackage.getPackName();
        LogUtil.log(String.format("versionCode: %s, versionName: %s, packName: %s"
                , versionCode, versionName, packName));
    }

    private void mvvmInit() {
        //是否开启日志打印
        KLog.init(true);
//配置全局异常崩溃操作
        CaocConfig.Builder.create()
                .backgroundMode(CaocConfig.BACKGROUND_MODE_SILENT) //背景模式,开启沉浸式
                .enabled(true) //是否启动全局异常捕获
                .showErrorDetails(true) //是否显示错误详细信息
                .showRestartButton(true) //是否显示重启按钮
                .trackActivities(true) //是否跟踪Activity
                .minTimeBetweenCrashesMs(2000) //崩溃的间隔时间(毫秒)
                .errorDrawable(R.mipmap.ic_launcher) //错误图标
                .restartActivity(Lesson1Activity.class) //重新启动后的activity
                //.errorActivity(YourCustomErrorActivity.class) //崩溃后的错误activity
                //.eventListener(new YourCustomEventListener()) //崩溃后的错误监听
                .apply();
    }
}
